<template>
	<uni-popup ref="inputDialog" type="dialog">
		<uni-popup-dialog cancelText="取消" confirmText="确定" title="发货" type="info" @close="$refs.inputDialog.close()"
			@confirm="dialogInputConfirm" before-close>

			<uni-forms :modelValue="entity" label-position="top" ref="form" style="width: 100%;" label-width="200">
				<uni-forms-item label="试用是否成功:" name="SampleStatus">
					<view>
						否
						<switch :checked="entity.SampleStatus ==1" style="transform:scale(0.7)"
							@change="SampleStatusChange" /> 是
					</view>
				</uni-forms-item>
				<uni-forms-item label="试用说明:" name="SampleTrialRemark">
					<uni-easyinput v-model="entity.SampleTrialRemark" placeholder="请输入地址" type="textarea" />
				</uni-forms-item>
			</uni-forms>
		</uni-popup-dialog>
	</uni-popup>
</template>

<script>
	import {
		// 样品反馈提交
		SPL_SampleApplyMainUpdateDataByCondition
	} from '@/api/interface.js'
	export default {
		props: {
			parentObj: {
				type: Object,
				default: () => {}
			}
		},
		data() {
			return {
				entity: {
					id: "",
					SampleStatus: 1
				},
			};
		},
		methods: {
			// 是否使用成功改变
			SampleStatusChange(event) {
				if (event.detail.value == true) {
					this.entity.SampleStatus = 1
				} else {
					this.entity.SampleStatus = 2
				}
			},
			// 样本反馈提交
			dialogInputConfirm(value) {
				var that = this
				console.log('确认了', value, this.entity)
				let searchArr = [];
				if (this.entity.SampleTrialRemark) {
					searchArr = [{
							Condition: "SampleTrialRemark",
							Keyword: this.entity.SampleTrialRemark
						},
						{
							Condition: "SampleStatus",
							Keyword: this.entity.SampleStatus
						}
					];
				} else {
					searchArr = [{
						Condition: "SampleStatus",
						Keyword: this.entity.SampleStatus
					}];
				}
				uni.showLoading({
					title: '反馈中'
				})
				SPL_SampleApplyMainUpdateDataByCondition({
						Conditions: searchArr,
						ids: [this.entity.Id]
					})
					.then(resJson => {
						if (resJson.Success) {
							that.$sucessToast('反馈成功')
							setTimeout(function() {
								that.parentObj.getDataList()
								uni.hideLoading()
							}, 2500)
							that.$refs.inputDialog.close()
						} else {
							that.$errorToast(resJson.Msg);
							setTimeout(function() {
								uni.navigateBack()
								uni.hideLoading()
							}, 2500)
							that.$refs.inputDialog.close()
						}
					});
			},
			openForm(Id) {
				console.log('获取打开后的id', Id)
				this.entity.Id = Id
				this.$refs.inputDialog.open()
			},
			confrim() {}
		}
	};
</script>

<style lang="less" scoped>
	::v-deep.uni-dialog-content {
		padding: 0 30rpx !important;
	}
</style>